package com.store.serviceimpl;

import com.store.mapper.CategoryMapper;
import com.store.mapper.ProductMapper;
import com.store.pojo.Category;
import com.store.pojo.Product;
import com.store.service.ForeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.List;

@Service
public class ForeServiceImpl implements ForeService {

    @Autowired
    CategoryMapper categoryMapper;

    @Autowired
    ProductMapper productMapper;

    /**
     * 查询所有的商品种类，例如：奶茶专区，甜品/蛋糕
     */
  //  @Override
//    public String findAllCategory(Model model) {
//        List<Category> categories = categoryMapper.findAllCategoryInfo(category);//加了Info
//        List<Product> productList = productMapper.findProductByCategories(categories);
//        model.addAttribute("categories", categories);
//        model.addAttribute("productList", productList);
//        return "forepage/index";
//    }

    @Override
    public String findAllCategoryInfo(Model model, Category category) {
        return null;
    }

    /**
     * 商品详细信息
     */
    @Override
    public String findProductByPid(Integer pid, Model model) {
        Product product = productMapper.findProductByPid(pid);
        if (product == null) {
            return "forepage/noPro";
        }
        System.out.println(product);
        model.addAttribute("product", product);
        return "forepage/proDetail";
    }

    @Override
    public String findAllCategory(Model model) {
        return null;
    }
}
